package com.rpay.dao.user;

import com.google.common.collect.Maps;
import com.rpay.model.contract.ContractDO;
import com.rpay.model.user.UserRippleDO;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * Title：
 * Description
 *
 * @author fxg06 on 2018/5/13
 * @version 1.0
 */
@Repository
public class UserRippleDao {
    @Autowired
    @Qualifier("writeSqlSession")
    private SqlSessionTemplate writeSqlSession;

    @Autowired
    @Qualifier("readSqlSession")
    private SqlSessionTemplate readSqlSession;

    public List<UserRippleDO> selectUserRipples(Integer userId, String date) {
        Map map = Maps.newHashMap();
        map.put("userId", userId);
        map.put("date", date);
        return readSqlSession.selectList("rpay.user.ripple.selectByDate", map);
    }

    public List<UserRippleDO> selectUserRipples(Integer userId) {
        return readSqlSession.selectList("rpay.user.ripple.selectByUserId", userId);
    }

    public int insert(UserRippleDO userRippleDO) {
        return readSqlSession.insert("rpay.user.ripple.insert", userRippleDO);
    }


    public BigDecimal selectTotalByUserId(Integer userId) {
        return readSqlSession.selectOne("rpay.user.ripple.selectTotalByUserId", userId);
    }

    public List<ContractDO> selectContract() {
        return readSqlSession.selectList("rpay.user.ripple.selectContract");
    }

}
